let phoneIpt = document.querySelector("#phoneIpt");// 手机号 input
let emailIpt = document.querySelector("#emailIpt");// 邮箱 input

let phoneSpan = document.querySelector("#phoneSpan");// 手机号 span
let emailSpan = document.querySelector("#emailSpan");// 邮箱 span

let changeSubmit = document.querySelector("#changeSubmit");// 提交按钮


let phoneType, // 手机号 flag
    emailType; // 邮箱 flag
let phoneTimer,
    emailTimer;

-function () {
    phoneType = /^[1][3456789][0-9]{9}$/.test(phoneIpt.value);
    emailType = /^[a-z0-9A-Z_]+@[a-z0-9A-Z.]+\.[a-z]{2,}$/.test(emailIpt.value);
    if (phoneType && emailType)
        changeSubmit.removeAttribute("disabled");
    else
        changeSubmit.disabled = "disabled";
}();

phoneIpt.oninput = function () {
    phoneType = /^[1][3456789][0-9]{9}$/.test(phoneIpt.value);
    checked();
};
emailIpt.oninput = function () {
    emailType = /^[a-z0-9A-Z_]+@[a-z0-9A-Z.]+\.[a-z]{2,}$/.test(emailIpt.value);
    checked();
};

function checked() {
    if (phoneType && emailType) {
        changeSubmit.removeAttribute("disabled");
        phoneSpan.style.display = "none";
        emailSpan.style.display = "none";
        return;
    } else if (!phoneType) {
        phoneSpan.style.display = "inline";
        if (phoneTimer != null)
            clearTimeout(phoneTimer);
        phoneTimer = window.setTimeout(function () {
            phoneSpan.style.display = "none";
            clearTimeout(phoneTimer);
            phoneTimer = null;
        }, 2000);
    } else if (!emailType) {
        emailSpan.style.display = "inline";
        if (emailTimer != null)
            clearTimeout(emailTimer);
        emailTimer = window.setTimeout(function () {
            emailSpan.style.display = "none";
            clearTimeout(emailTimer);
            emailTimer = null;
        }, 2000);
    }
    changeSubmit.disabled = "disabled";
}

